<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style>
      button {
        height: 50px;
        width: 150px;
        border: 2px solid #aaa;
        background: rgb(112, 171, 248);
        color: #fff;
        border-radius: 25px;
        font-size: 22px;
      }
    </style>
  </head>
  <body>
    <button id="red">红色</button>
    <button id="yellow">黄色</button>
    <button id="pink">粉色</button>

    <script>
      var body = document.getElementsByTagName("body")[0];
      var btnRed = document.getElementById("red");
      var btnYellow = document.getElementById("yellow");
      var btnPink = document.getElementById("pink");
      //   console.log(btnRed);
      function color(obj, body, color) {
        obj.onclick = function () {
          body.style.background = color;
        };
      }

      function hover(obj, startColor, endColor) {
        // 鼠标移入事件onmouseover
        obj.onmouseover = function () {
          obj.style.background = startColor;
        };
        // 鼠标移出事件onmouseout
        obj.onmouseout = function () {
          obj.style.background = endColor;
        };
      }
      hover(btnRed, "#666", "rgb(112, 171, 248)");
      color(btnRed, body, "red");
      color(btnYellow, body, "yellow");
      color(btnPink, body, "pink");
    </script>
  </body>
</html>
